<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="车牌号" prop="numberPlate">
        <el-input
          v-model="queryParams.numberPlate"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker clearable
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-date-picker clearable
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="recordList">
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="车牌号" align="center" prop="numberPlate" />
      <el-table-column label="当前停车场" align="center" prop="parkId">
       <template slot-scope="scope">
          <div v-for="item in parkLists" :key="item.id" v-if="item.id==scope.row.parkId">
          {{item.name}}</div>
        </template></el-table-column>
      <el-table-column label="联系方式" align="center" prop="phone" />
      <el-table-column label="当前状态" align="center" prop="state">
       <template slot-scope="scope">
          <dict-tag :options="dict.type.park_car_state" :value="scope.row.state"/>
        </template></el-table-column>
      <el-table-column label="入场放行方式" align="center" prop="type">
         <template slot-scope="scope">
          <dict-tag :options="dict.type.park_car_in_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="user" />
      <el-table-column label="匝道口" align="center" prop="checkpointName" />
      <el-table-column label="进场时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="离场时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/park/record";
import {getAllParkingLoat}  from "@/api/park/park"
export default {
  name: "Record",
  dicts: ['park_car_in_type', 'park_car_state'],
  data() {
    return {
      // 遮罩层
      loading: true,

      showSearch: true,
      // 总条数
      total: 0,
      // 车辆通行记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        numberPlate: null,
        startTime: null,
        endTime: null,
      },
      // 表单参数
      form: {},

      parkLists:[],

    };
  },
  created() {
    this.getList();
    this.doGetAllParkingLoat();
  },
  methods: {

    doGetAllParkingLoat(){
          getAllParkingLoat().then(res=>{
            this.parkLists = res.data;
      })
    },

    /** 查询车辆通行记录列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
